#include "QtLaser.h"
#include <QPainter>
#include "QtBlendToEffect.h"
#include "QtSequentialAnimationEffect.h"
#include "QtScaleToEffect.h"
#include "QtRotateToEffect.h"

QtLaser::QtLaser(const Direction& direction, QtSprite *parent): QtCellSprite(parent), duration(1000), headDirection(direction)
{
	SetDirection(direction);

	laserBeam = new QtLineSprite();
	laserBeam->SetColor(Qt::red);
	laserBeam->SetLineWidth(3);
	laserBeam->SetDepth(10);
	DisableLaser();

	AddSprite(laserBeam);

	SetResource("foreground", "laser");
}

QtLaser::~QtLaser()
{
	if (laserBeam)
	{
		delete laserBeam;
		laserBeam = 0;
	}
}

void QtLaser::SetLaserColor(QColor color)
{
	laserBeam->SetColor(color);
}

void QtLaser::SetDirection(const Direction& direction)
{
	headDirection = direction;

	switch(headDirection.Type())
	{
		case Direction::NORTH:
			SetAngle(0);
		break;

		case Direction::SOUTH:
			SetAngle(180);
		break;
	
		case Direction::WEST:
			SetAngle(270);
		break;
	
		case Direction::EAST:
			SetAngle(90);
		break;
	}
}


void QtLaser::EnableLaser()
{
	QPointF beginPoint = MapToScene(QPointF(Background()->Width()/2, Height()));
	laserBeam->SetLine(beginPoint, laserDestination);

	laserBeam->Show();
}

void QtLaser::DisableLaser()
{
	laserBeam->Hide();
}

void QtLaser::SetLaserDestination(const QPointF& pos)
{
	laserDestination = pos;
}

void QtLaser::BackgroundUpdated()
{
	SetCenterPoint(QPointF(Background()->Width()/2, Background()->Height()/2));
}



